/*
 * Copyright 2010 Biz-e (info@biz-e.nl)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.biz_e.acl.client;

import java.util.List;

import nl.biz_e.acl.shared.model.User;
import nl.biz_e.acl.shared.model.UserGroup;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

/**
 * Handles all server side user and usergroup logic.
 * 
 * @author Joost A. Bloemsma
 * 
 */
@RemoteServiceRelativePath("user")
public interface UserService extends RemoteService {
    /**
     * Persists the passed {@link User}
     * 
     * @param user
     * @return The persisted user, with filled in Id.
     */
    public User saveUser(User user);

    /**
     * Deletes the passed user from the datastore
     * 
     * @param user
     */
    public void deleteUser(User user);

    /**
     * Persists the passed {@link UserGroup}
     * 
     * @param group
     * @return The persisted usergroup, with filled in Id.
     */
    public UserGroup saveUserGroup(UserGroup group);

    /**
     * Deletes the passed usergroup from the datastore
     * 
     * @param group
     */
    public void deleteUserGroup(UserGroup group);

    /**
     * Creates a user-usergroup relation
     * 
     * @param user
     * @param group
     * @return {@code true} if success
     */
    public Boolean setMembership(User user, UserGroup group);

    /**
     * Removes a user-usergroup relation
     * 
     * @param user
     * @param group
     */
    public void deleteMembership(User user, UserGroup group);

    /**
     * Returns a list of all group members
     * 
     * @param group
     * @return a list of users
     */
    public List<User> getGroupMembers(UserGroup group);

    /**
     * Returns a list of all groups the passed user is a member of.
     * 
     * @param user
     * @return a list of groups
     */
    public List<UserGroup> getMemberships(User user);

}
